//
//  UIColor+BZTheme.m
//  MZBasic
//
//  Created by Sings on 2022/8/11.
//

#import "UIColor+BZTheme.h"

@implementation UIColor (BZTheme)

//+ (UIColor *)skin_main_color {
//    return [UIColor grayColor];
//}

+ (UIColor *) color1 {
    return [UIColor blueColor];
}

+ (instancetype) BZTheme_colorWithKey:(NSString *)colorKey DefaultColor:(UIColor *) defaultColr {
    if (defaultColr == nil) {
        defaultColr = [UIColor whiteColor];
    }
    const char *str = [BZThemeKeyToStr(colorKey) cStringUsingEncoding:NSUTF8StringEncoding];
    if (str == NULL) {
        return defaultColr;
    }
    int num = 0;
    sscanf(str, "%x", &num);
    UIColor *color = [UIColor colorWithRed:((float)((num & 0xFF0000) >> 16)) / 255.0                           \
                           green:((float)((num & 0xFF00) >> 8)) / 255.0                              \
                            blue:((float)(num & 0xFF)) / 255.0                                       \
                           alpha:1];
    return color;
}

+ (instancetype) BZTheme_colorWithKey:(NSString *) colorKey {
    const char *str = [BZThemeKeyToStr(colorKey) cStringUsingEncoding:NSUTF8StringEncoding];
    if (str == NULL) {
        return [UIColor whiteColor];
    }
    int num = 0;
    sscanf(str, "%x", &num);
    return [UIColor colorWithRed:((float)((num & 0xFF0000) >> 16)) / 255.0                           \
                           green:((float)((num & 0xFF00) >> 8)) / 255.0                              \
                            blue:((float)(num & 0xFF)) / 255.0                                       \
                           alpha:1];
}

+ (CGColorRef)BZTheme_cgcolorWithKey:(NSString *)colorKey {
    UIColor *color = [self BZTheme_colorWithKey:colorKey];
    return color.CGColor;
}

+ (instancetype) BZTheme_color:(NSString *) colorPath {
    SEL sel = NSSelectorFromString(colorPath);
    if ([[UIColor class] respondsToSelector:sel]) {
        return ((UIColor  * (*)(id, SEL))(void *) objc_msgSend)((id)[UIColor class], sel);
    }else {
        return [UIColor BZTheme_colorWithKey:colorPath];
    }
}

@end
